package com.example.demo;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class TestThread2 extends Thread{
    private String url;
    private String name;
    TestThread2(String url,String name){
        this.url=url;
        this.name=name;
    }
    @Override
    public void run() {
        WebDownloader webDownloader = new WebDownloader();
        webDownloader.downloader(url,name);
        System.out.println("文件名"+name);
    }

    public static void main(String[] args) {
        TestThread2 t1 = new TestThread2("https://himg2.huanqiucdn.cn/attachment2010/2019/0828/20190828082005330.jpg","1.jpg");
        TestThread2 t2 = new TestThread2("https://p1.ssl.img.360kuai.com/t0156652d49d67d77c0.jpg","2.jpg");
        TestThread2 t3 = new TestThread2("https://n.sinaimg.cn/sinakd10116/360/w1600h1160/20210223/4b4c-kkmphps5057347.jpg","3.jpg");
        t1.start();
        t2.start();
        t3.start();

    }
}
class WebDownloader{
    public void downloader(String url,String name){
        try {
            FileUtils.copyURLToFile(new URL(url),new File(name));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("io异常");
        }

    }
}